import request from '@/utils/request';
// import { reject, resolve } from 'core-js/fn/promise';

/**
 *获取我的课程列表
 * @param {*} showCount
 * @param {*} currentPage
 *
 */
export const getMyCourseList = () => {
  return request.post('/album/getMyAlbumList', {
    // params: {
    //   type: 1,
    // },
    type: '1', // 字符串
  });
};

export const upLoadFile = (formData) => {
  return new Promise((resolve, reject) => {
    request
      .post('/beiJing/shangchuanTomcat', formData, { loading: 1 })
      .then((res) => {
        // console.log(res);
        // this.$message({
        //   message: '图片上传成功!',
        //   type: 'success',
        // });
        resolve(res);
        // this.chooseImg = res.data.filePath;
      })
      .catch((err) => {
        // console.log(err);
        reject(err);
        // this.$message.error('图片上传失败!');
      });
  });
};

export const upLoadMediaFile = (formData) => {
  return new Promise((resolve, reject) => {
    request
      .post('/beiJing/upload', formData, { loading: 1, timeout: 3000000 })
      .then((res) => {
        // console.log(res);
        // this.$message({
        //   message: '图片上传成功!',
        //   type: 'success',
        // });
        resolve(res);
        // this.chooseImg = res.data.filePath;
      })
      .catch((err) => {
        // console.log(err);
        reject(err);
        // this.$message.error('图片上传失败!');
      });
  });
};

/**
 *保存课程
 */
export const saveCourse = ({ album_title, album_desc, album_cover_urlalbum, purchase_price }) => {
  return request.post('/album/saveAlbum', {
    album_title,
    album_desc,
    album_cover_urlalbum,
    purchase_price,
    type: '1',
  });
};

/**
 *编辑课程
 */
export const editCourse = ({ album_id, album_title, album_desc, album_cover_urlalbum, purchase_price }) => {
  return request.post('/album/editAlbum', {
    album_id,
    album_title,
    album_desc,
    album_cover_urlalbum,
    purchase_price,
  });
};

/**
 * 删除课程
 */
export const deleteCourse = ({ album_id }) => {
  return request.post('/album/deleteAlbum', {
    album_id,
  });
};

/**
 * 获取课程基本信息
 */
export const getCourse = ({ album_id }) => {
  return request.post('/album/getAlbum', {
    album_id,
  });
};

/**
 * 小节列表
 * @param {*} param0
 * @returns
 */
export const getChapterList = ({ album_id, currentPage, showCount }) => {
  return request.post('/albumInfo/getAlbumInfoList', {
    album_id,
    type: '1',
    currentPage,
    showCount,
  });
};

/**
 * 获取小节 信息
 * @param {*} param0
 * @returns
 */
export const getChapterDetail = ({ album_info_id }) => {
  return request.post('/albumInfo/getAlbumInfo', {
    album_info_id,
  });
};

/**
 * 保存小节 信息
 * @param {*} param0
 * @returns
 */
export const saveChapterDetail = ({
  album_info_title,
  album_info_time_size,
  audio_address,
  video_address,
  sort,
  album_id,
  is_need_pay,
}) => {
  return request.post('/albumInfo/saveAlbumInfo', {
    type: '1',
    album_info_title,
    album_info_time_size,
    audio_address,
    video_address,
    sort,
    album_id,
    is_need_pay,
  });
};

/**
 * 编辑小节 信息
 * @param {*} param0
 * @returns
 */
export const editChapterDetail = ({
  album_info_title,
  album_info_time_size,
  audio_address,
  video_address,
  sort,
  album_id,
  is_need_pay,
  album_info_id,
}) => {
  return request.post('/albumInfo/editAlbumInfo', {
    type: '1',
    album_info_title,
    album_info_time_size,
    audio_address,
    video_address,
    sort,
    album_id,
    is_need_pay,
    album_info_id,
  });
};

/**
 * 删除小节 信息
 * @param {*} param0
 * @returns
 */
export const deleteChapterDetail = ({ album_info_id }) => {
  return request.post('/albumInfo/deleteAlbumInfo', {
    album_info_id,
  });
};
